
def main():
    
    N, M = map(int, input().split())
    
    grid = []
    for i in range(N):
        grid.append(list(map(int, input().split())))
    
    cover_edge = 0
    num_island = 0
    
    for i in range(N):
        for j in range(M):
            if grid[i][j] == 1:
                num_island += 1
                
                if i > 0 and grid[i-1][j] == 1:
                    cover_edge += 1
                if j > 0 and grid[i][j-1] == 1:
                    cover_edge += 1
    
    res = num_island * 4 - cover_edge * 2
    print(res)

main()